#!/bin/sh
# - message_threads
# - worker_threads
# - runtime
# - iterations
# - intervaltime_s

. $LKP_SRC/lib/reproduce-log.sh
. $LKP_SRC/lib/debug.sh

cd $BENCHMARK_ROOT/schbench || die "no $BENCHMARK_ROOT/schbench"

: [ -n "$worker_threads" ] || worker_threads=16
: [ -n "$runtime" ] || runtime=300

# to avoid "core dumped", set message_threads to default 2 if message_threads
# is 0 because message_threads is used as denominator in schbench command.
# please note that 2 is a default value from schbench command, as below:
# schbench usage:
#     -m (--message-threads): number of message threads (def: 2)
#     ...

[ $message_threads -eq 0 ] && message_threads=2

[ -n "$intervaltime_s" ] && interval_opt="-i $intervaltime_s"

# the source code print the output to stderr, here redirection stderr to stdout
for i in $(seq $iterations)
do
	echo Iteration : $i
	log_cmd ./schbench -m $message_threads -t $worker_threads -r $runtime $interval_opt 2>&1 || die "Schbench run failed"
done
